#include <stdlib.h>
#include <stdio.h>

/*打印数组的全排列*/

void array_cpy (int* dst, const int* src, const int len, const int excep)
{
    int i, j=0;
    for (i = 0; i < len; i++)
    {
        if ( i != excep)
        {
            *(dst+j) = *(src+i);
            j++;
        }
    }
}

int count = 0;

void print_a (int* p, const int len)
{
    if ( len > 1 )
    {
        int i;
        for (i = 0; i < len; i++)
        {
            printf (" %d ", *(p+i));
            int * dst = (int*)malloc ((len-1)*4);
            array_cpy (dst, p, len, i);
            print_a (dst, len-1);
            free(dst);
        }
    }
    else
    {
        printf (" %d \t %d", *p, __LINE__);
        printf ("\n");
    count++;
    }
}

int main (void)
{
    int a[5] = {1,2,3,4,5};
    print_a (a, 5);
    printf ("count is %d\n", count);
    return 0;
}
